<%@page import="java.sql.Connection"%>
<%@ page language="java" import="java.lang.*" import="java.sql.*" %>

<HTML>
    <BODY>
        <%
                    Connection con = null;

                    String rep = request.getParameter("empname");
                    String code = (String) request.getParameter("empid");
                    int ID = Integer.parseInt(code);
                    try {
                        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                        con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=JspJavaScript", "sa", "fat123456");
                        String rec = "UPDATE Employee SET empname='" + rep + "' where empid='" + ID + "'";

                        Statement stmt = null;
                        stmt = con.createStatement();
                        int mod = stmt.executeUpdate(rec);
                        if (mod == 0) {%>
        <script language="javascript">
            alert("This Emp ID already Exists");
            document.location="EmployeeInformation.jsp";
        </script>
        <%    }
    if (mod == 1) {%>
        <script language="javascript">
            alert("Record Updated Successfully");
        document.location="EmployeeInformation.jsp";
        </script>
        <%    }
            con.commit();
            stmt.close();
            con.close();

        } catch (Exception e) {%>
        <script language="javascript">
            alert("Please Enter New Name");
            document.location="EmployeeInformation.jsp";
        </script>
        <%            }

        %>
    </BODY>
</HTML>